<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户账户表
class New_task_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'new_task';
        $this->users = 'users';
        $this->users_info = 'users_info';
    }
    
    function get($where){
        return $this->db->where($where)->get($this->table)->row_array();
    }
    
    function get_list($where,$page,$limit){
        $this->db->select($this->table.".*,".$this->users.".username,".$this->users_info.".nickname");
        $this->db->from($this->table);
        $this->db->join($this->users, $this->users.'.user_id = '.$this->table.'.user_id', 'left');
        $this->db->join($this->users_info, $this->users_info.'.user_id = '.$this->table.'.user_id', 'left');
        $this->db->where($where);
        $this->db->order_by('receive_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_task($user_id){
        $this->db->select($this->table.".*");
        $this->db->from($this->table);
        $this->db->where('user_id',$user_id);
        $this->db->order_by('step','asc');
        return $this->db->get()->result_array();
    }
    
    function insert($data){
        $this->db->insert($this->table, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update($data,$where){
        return $this->db->where($where)->update($this->table, $data);
    }
    
    
}
